package com.wyh.filemanager;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

import com.wyh.filemanager.model.SettingUtil;
import com.wyh.filemanager.util.FileUtil;
import com.wyh.log.MyLog;

public class SettingActivity extends PreferenceActivity implements
		OnPreferenceChangeListener, OnPreferenceClickListener {

	private static final String TAG = "SettingActivity";

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		addPreferencesFromResource(R.xml.activity_setting);

		SharedPreferences settingShared = PreferenceManager
				.getDefaultSharedPreferences(this);

		Preference defaultPath = (Preference) findPreference("defaultpath");
		defaultPath.setSummary(settingShared.getString("defaultpath",
				FileUtil.getSDCardPath()));

		defaultPath.setOnPreferenceChangeListener(this);

		// Preference showHiddenFile = findPreference("showhiddenfile");
		//
		// Preference showSystemSpace = findPreference("showsystemspace");

	}

	@Override
	public boolean onPreferenceChange(Preference preference, Object newValue) {
		if (preference.getKey().equals("defaultpath")) {
			preference.setSummary((String) newValue);
			MyLog.info(TAG, "defaultpath change to " + newValue);
		}
		SettingUtil.getInstanse().initData();
		return true;
	}

	@Override
	public boolean onPreferenceClick(Preference preference) {
		if (preference.getKey().equals("defaultpath")) {

		}
		return false;
	}

	@Override
	protected void onDestroy() {
		SettingUtil.getInstanse().initData();
		super.onDestroy();
	}

}
